package com.yanqu.road.server.logic.activity.condition;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.rank.yrank.UserYRank;
import com.yanqu.road.logic.helper.UnionActivityGroupHelper;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.manger.rank.YRankMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.pb.PlayerPb;

public abstract class BaseUserYRankCondition extends BaseActivityCondition {

    public BaseUserYRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    protected void rankChange() {
        int activityId = activityConditionInfo.getActivityId();
        long userId = player.getUserId();
        int groupId = GameUnionActivityGroupMgr.getGroupId(activityId, userId);
        if (groupId == UnionActivityGroupHelper.NO_GROUP_ID) {
            return;
        }
        UserBaseInfo userBaseInfo = PlayerBasePb.parseBaseUserInfo(PlayerPb.parsePlayerBaseTempMsg(player.getUserInfo()).build());

        UserYRank userYRank = new UserYRank();
        userYRank.setActivityId(activityId);
        userYRank.setGroupId(groupId);
        userYRank.setIdKey(String.valueOf(activityConditionInfo.getType()));
        userYRank.setUserId(userId);
        userYRank.setUserBaseInfo(userBaseInfo);
        userYRank.setValue(getValue());
        userYRank.setParam(getParam());
        userYRank.setUpdateTime(System.currentTimeMillis());
        YRankMgr.addUserYRankCache(userYRank);
    }

}
